package com.study.model.enums;

import lombok.Getter;

/**
 * 用户角色枚举
 */
@Getter
public enum UserRoleEnum {
    ADMIN("管理员", "admin"),
    USER("普通用户", "user");

    private final String roleName;
    private final String value;

    UserRoleEnum(String roleName, String value) {
        this.roleName = roleName;
        this.value = value;
    }

    /**
     * 根据value获取枚举对象
     * @param value
     * @return
     */
    public static UserRoleEnum getEnumByValue(String value) {
        if (value == null) {
            return null;
        }
        for (UserRoleEnum anEnum : UserRoleEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }
}
